//defineStore pina写法
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userGetInfoService } from '@/api/user.js'

export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref('')
    const user = ref({})
    const getUser = async () => {
      const res = await userGetInfoService()
      console.log(res)
      user.value = res.data.data
    }
    const setToken = (newToken) => {
      token.value = newToken
    }
    const setUser = (newUser) => {
      user.value = newUser
    }
    return {
      token,
      setToken,
      getUser,
      setUser,
      user
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'big-user',
          storage: localStorage
        }
      ]
    }
  }
)
